package com.steel.yfmall.cloud.assistant.listener;

import com.alibaba.fastjson.JSON;
import com.steel.yfmall.cloud.assistant.po.stock.SteelBaseFreightBean;
import com.steel.yfmall.cloud.assistant.po.view.OutCallApiLogBean;
import com.steel.yfmall.cloud.assistant.view.OutCallApiLogBeanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: OutCallApiLogListener
 * @Package com.steel.yfmall.cloud.assistant.listener
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/1/22 17:34
 */
@Slf4j
@Component
public class OutCallApiLogListener {

    @Resource
    private OutCallApiLogBeanService outCallApiLogBeanService;

    /**
     * 新增对外接口访问日志
     * @Title: doInsertOutCallApiLogBeanSync
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param onMsgText 参数说明
     * @return void    返回类型
     * @author yuchaohua
     * @date 2021/1/22 17:40
     */
    @JmsListener(destination = "insert_out_call_api_log")
    public void doInsertOutCallApiLogBeanSync(String onMsgText) {
        OutCallApiLogBean paraBean = null;
        try {
            if (log.isDebugEnabled()){
                log.info("OutCallApiLogListener  doInsertOutCallApiLogBeanSync  insert_out_call_api_log: " + onMsgText);
            }
            if (StringUtils.isBlank(onMsgText)) {
                log.error("新增对外接口访问日志:参数为空！");
                return;
            }
            paraBean = JSON.parseObject(onMsgText, OutCallApiLogBean.class);
            if (paraBean == null ) {
                log.error("新增对外接口访问日志必传参数为空：" + onMsgText);
                return;
            }
            if (!outCallApiLogBeanService.insertOutCallApiLogBean(paraBean)) {
                log.error("新增对外接口访问日志信息失败:" + JSON.toJSONString(paraBean));
            }
        } catch (Exception e) {
            log.error("新增对外接口访问日志失败: " + onMsgText, e);
        }
    }

}
